//
//  NetworkManager.m
//  OC_Poj_demo
//
//  Created by weixin on 2018/6/24.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "NetworkManager.h"

@interface NetworkManager()

@property (nonatomic, strong) AFNetworkReachabilityManager *reachabilityMng;

@end

@implementation NetworkManager

+ (instancetype)shareManager{
    static NetworkManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[self alloc] init];
    });
    return manager;
}

- (void)startReachbility{
    @weakify(self);
    [self.reachabilityMng setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        @strongify(self);
        switch (status){
            case AFNetworkReachabilityStatusReachableViaWWAN:
                self->_network = YES;

                break;
                
            case AFNetworkReachabilityStatusReachableViaWiFi:
                self->_network = YES;

                break;
                
                //没有授权
            case AFNetworkReachabilityStatusNotReachable:
            case AFNetworkReachabilityStatusUnknown:
                self->_network = NO;

                break;
                
            default:
                break;
        }
    }];
    // 开始监听
    [self.reachabilityMng startMonitoring];
}

- (void)stopReachbility{
    // 停止监听
    [self.reachabilityMng stopMonitoring];
}

- (AFNetworkReachabilityManager *)reachabilityMng{
    if (!_reachabilityMng){
        _reachabilityMng = [AFNetworkReachabilityManager sharedManager];
    }
    return _reachabilityMng;
}



@end
